# -*- coding: utf-8 -*-
# @时间      : 2025/4/14 下午3:02
# @作者      : hhh
from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def index():
    url = "https://deyunce:828123@mall.deyunce.com/pc/"
    service = Service(executable_path='chromedriver.exe')
    driver = webdriver.Chrome(service=service)
    # wait = WebDriverWait(driver,10)
    driver.get(url)
    driver.maximize_window()
    driver.implicitly_wait(10)
    return driver

def find_click(driver,x):  #driver是一个参数
    wait = WebDriverWait(driver, 10)
    wait.until(EC.visibility_of_element_located((By.XPATH,x)))
    ele = driver.find_element(By.XPATH,x)
    wait.until(EC.element_to_be_clickable(ele))
    ele.click()
    sleep(5)

#第二个工具只用一次 立即登录的时候使用: 点击立即登录的时候要找多个 我只用第二个
def finds_click(driver,x):
    wait = WebDriverWait(driver, 10)
    wait.until(EC.visibility_of_any_elements_located((By.XPATH, x)))  # 由于有两个点击按键 any
    ele = driver.find_elements(By.XPATH, x)[1]  # 同理 需要在这个列表中elements 去拿第二个所以加下标[1]
    wait.until(EC.element_to_be_clickable(ele))
    ele.click()

#第三个工具 输入文字 send  输入账号和 密码的时候使用
def send_wd(driver,x,word):
    wait = WebDriverWait(driver, 10)
    wait.until(EC.visibility_of_element_located((By.XPATH,x)))
    ele = driver.find_element(By.XPATH,x)
    wait.until(EC.visibility_of(ele))
    ele.send_keys(word)



if __name__ == '__main__':
# '//a[text()="登录"]'
    # '//div[contains(text(),\'账号密码登录\')]'
    # '//input[@placeholder="请输入账号/手机号码"]' '每个人的手机号'
    # '//input[@placeholder="请输入密码"]'    '每个人的密码'
    # '//span[text()="立即登录"]'
    # '//a[@href="/pc/user/profile"]'
    # '//div[@class="lighter xs item"]'
    driver = index()
    find_click(driver,'//a[text()="登录"]')

    find_click(driver,'//div[contains(text(),\'账号密码登录\')]')

    send_wd(driver,'//input[@placeholder="请输入账号/手机号码"]','15075670661')

    send_wd(driver,'//input[@placeholder="请输入密码"]','15075670661')

    finds_click(driver,'//span[text()="立即登录"]')

    find_click(driver,'//a[@href="/pc/user/profile"]')

    find_click(driver,'//div[@class="lighter xs item"]')













